package com.health.fragment.focusgroup.child;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.FWMYDPJActivity;
import com.health.NovaApplication;
import com.health.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.focusgroup.ChildActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CHILD_TCMHM_ONE;
import com.health.tablebean.CHILD_WITHIN_ONE_YEAR_OLD;
import com.health.tools.DateUtil;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;
import com.novabluetooth.views.ExamHistoryActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
 * 1岁内检查-6月龄健康检查记录表
 * 
 * @author 鹿云龙
 */
public class CheckFragment1_3 extends NovaFragment implements onFragmentSave, OnClickListener {
	private EditText et_ewg;// 耳外观
	private EditText et_kq;// 口腔
	private EditText et_fb;// 腹部
	private EditText et_sz;// 四肢
	private EditText et_pf;// 皮肤
	private View baseView = null;
	private ARCHIVE_BASEINFO userInfo;// 基本信息
	/*** 上，中，下 */
	private List<BD_DD_INFO> lstszx;
	/*** 无、有 */
	private List<BD_DD_INFO> lstyw;
	/** 未见异常 */
	private List<BD_DD_INFO> lstyc;
	/** 未脱，脱落 */
	// private List<BD_DD_INFO> lstqb;
	private MyGridView mgvtizhong;// 体重
	private MyGridView mgvshenchang;// 身长
	private MyGridView mgvmianse;// 面色
	private MyGridView mgvqianxin;// 前囟
	private MyGridView mgvyanwaiguan;// 眼外观
	private MyGridView mgvtingli;// 听力
	private MyGridView mgvxinfei;// 心肺
	// private MyGridView mgvqibu;// 脐部

	private MyGridView mgv_gangmen;// 肛门
	private MyGridView mgvpifu;// 皮肤
	private MyGridView mgvjingbubaokuai;// 颈部包块
	private MyGridView mgverwaiguan;// 耳部外观
	// private MyGridView mgvkouqiang;// 口腔
	private MyGridView mgvfubu;// 腹部
	private MyGridView mgvsizhi;// 四肢

	private NiceSpinner ns_kyglbzz;// 可疑佝偻病症状
	private NiceSpinner ns_kyglbtz;// 可疑佝偻病体征
	// 发育评估
	private MyGridView mgv_fayupinggu;
	/**
	 * 两次随访间患病相关
	 **/
	private MyGridView mgv_liangcisuifang;
	private EditText et_hbfy;
	private EditText et_hbfx;
	private EditText et_hbws;
	private EditText et_hbqt;
	/** 指导mgv_zhidao */
	private MyGridView mgv_zhidao;
	// 中医健康管理服务
	private MyGridView zhongyi;
	EditTextWithDate suiFang_Date;// 随访日期
	EditTextWithDate nextSuiFangDAte;// 下次随访日期
	EditText weightEdit;// 体重
	EditText shenChangEdit;// 身长
	EditText touWeiEdit;// 头围
	/** radioButtonAdapter */
	RadioButtonAdapter rbatizhong;// 体重
	RadioButtonAdapter rbashenchang;// 身长
	RadioButtonAdapter rbamianse;// 面色
	RadioButtonAdapter rbaqx;// 前囟
	RadioButtonAdapter rbaywg;// 眼外观
	RadioButtonAdapter rbatl;// 听力
	RadioButtonAdapter rbaxf;// 心肺
	// RadioButtonAdapter rbaqb;// 脐部
	RadioButtonAdapter rbagm;// 肛门
	RadioButtonAdapter rbapf;// 皮肤
	RadioButtonAdapter rbajbbk;// 颈部包块
	RadioButtonAdapter rbaewg;// 耳外观
	// RadioButtonAdapter rbakq;// 口腔
	RadioButtonAdapter rbafb;// 腹部
	RadioButtonAdapter rbasz;// 四肢
	CheckBoxAdapter rbafy;// 发育评估
	RadioButtonAdapter rbalc;// 两次随访
	CheckBoxAdapter cbazhidao;// 指导
	CheckBoxAdapter cbazy;
	EditText qianxinLeft;// 前囟左
	EditText qianxinRight;// 前囟右
	EditText xueDanBai;// 血红蛋白
	EditText huWai;// 户外活动
	EditText vcEditText;// 服用维生素
	NiceSpinner doctor;// 随访医生
	EditText zhongyi_other;// 中医药健康管理服务
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	private RadioGroup rd_zz;// 是否转诊
	private RadioButton rb_w;
	private RadioButton rb_y;
	private String str_zzId = "";

	private EditText ed_zzyy;
	private EditText ed_jg_ys;
	private Button btn_tz_more;
	private Button btn_xhdb_more;
	List<EditText> lstTv;

	@Override
	public View findViews(LayoutInflater inflater) {
		baseView = inflater.inflate(R.layout.child_check_fragment1_3, null);
		// 获取医生编号
		userInfo = NovaApplication.getUserInfo();

		setupView(baseView);
		GlobalConts.setMaxLength(2, huWai);
		GlobalConts.setMaxLength(50, et_pf, et_kq, ed_zzyy, ed_jg_ys, zhongyi_other, ed_zzyy, ed_jg_ys);
		GlobalConts.setMaxLength(5, vcEditText, xueDanBai, weightEdit, touWeiEdit, shenChangEdit, qianxinLeft,
				qianxinRight);
		GlobalConts.keep2decimal(weightEdit, vcEditText, shenChangEdit, touWeiEdit, huWai, xueDanBai);
		GlobalConts.setMaxLength(100, et_hbqt);
		addListener();
		setData();
		bind();
		return baseView;
	}

	/**
	 * 获取下拉框中需要的数据的信息
	 * 
	 * @param datas
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月16日 下午3:47:00
	 */
	private ArrayList<String> getDataInfo(List<BD_DD_INFO> datas) {
		ArrayList<String> infos = new ArrayList<String>();
		for (BD_DD_INFO bd : datas) {
			infos.add(bd.getDATAINFO());
		}
		return infos;
	}

	@Override
	public void setupView(View view) {
		suiFang_Date = (EditTextWithDate) baseView.findViewById(R.id.etw_date1);
		nextSuiFangDAte = (EditTextWithDate) baseView.findViewById(R.id.next_edit);
		suiFang_Date.setBefore(true);
		nextSuiFangDAte.setAfter(true);
		suiFang_Date.setText(sdf.format(new Date(System.currentTimeMillis())));
		mgvtizhong = (MyGridView) baseView.findViewById(R.id.mgvtizhong);
		mgvshenchang = (MyGridView) baseView.findViewById(R.id.mgvshenchang);
		mgvmianse = (MyGridView) baseView.findViewById(R.id.mgvmianse);
		mgvqianxin = (MyGridView) baseView.findViewById(R.id.mgvqianlu);
		mgvyanwaiguan = (MyGridView) baseView.findViewById(R.id.mgvyanwaiguan);
		mgvtingli = (MyGridView) baseView.findViewById(R.id.mgvtingli);
		mgvxinfei = (MyGridView) baseView.findViewById(R.id.mgvxinfei);
		// mgvqibu = (MyGridView) baseView.findViewById(R.id.mgvqibu);

		mgv_gangmen = (MyGridView) baseView.findViewById(R.id.mgv_gangmen);
		mgvpifu = (MyGridView) baseView.findViewById(R.id.mgvpifu);
		mgvjingbubaokuai = (MyGridView) baseView.findViewById(R.id.mgvjingbubaokuai);
		mgverwaiguan = (MyGridView) baseView.findViewById(R.id.mgverwaiguan);
		// mgvkouqiang = (MyGridView) baseView.findViewById(R.id.mgvkouqiang);
		mgvfubu = (MyGridView) baseView.findViewById(R.id.mgvfubu);
		mgvsizhi = (MyGridView) baseView.findViewById(R.id.mgvsizhi);
		ns_kyglbzz = (NiceSpinner) baseView.findViewById(R.id.ns_kyglbzz);
		ns_kyglbtz = (NiceSpinner) baseView.findViewById(R.id.ns_kyglbtz);
		mgv_fayupinggu = (MyGridView) baseView.findViewById(R.id.mgv_fayupinggu);
		mgv_liangcisuifang = (MyGridView) baseView.findViewById(R.id.mgv_liangcisuifang);
		mgv_zhidao = (MyGridView) baseView.findViewById(R.id.mgv_zhidao);
		zhongyi = (MyGridView) baseView.findViewById(R.id.zhongyi);
		weightEdit = (EditText) baseView.findViewById(R.id.weight_edit);
		shenChangEdit = (EditText) baseView.findViewById(R.id.et_xuechangguiqita);
		touWeiEdit = (EditText) baseView.findViewById(R.id.et_jtzz);
		qianxinLeft = (EditText) baseView.findViewById(R.id.qianxin_left);
		qianxinRight = (EditText) baseView.findViewById(R.id.qianxin_right);
		xueDanBai = (EditText) baseView.findViewById(R.id.xuedanbai_edit);
		huWai = (EditText) baseView.findViewById(R.id.huwai_edit);
		vcEditText = (EditText) baseView.findViewById(R.id.vc_edit);
		doctor = (NiceSpinner) baseView.findViewById(R.id.doctor);
		GlobalConts.doctorList(doctor);
		zhongyi_other = (EditText) baseView.findViewById(R.id.zhongyi_other);
		et_ewg = (EditText) baseView.findViewById(R.id.et_ewg);
		et_kq = (EditText) baseView.findViewById(R.id.chuyashu);
		et_fb = (EditText) baseView.findViewById(R.id.et_fb);
		et_sz = (EditText) baseView.findViewById(R.id.et_sz);
		et_pf = (EditText) baseView.findViewById(R.id.et_pf);
		ed_zzyy = (EditText) baseView.findViewById(R.id.ed_zzyy);
		ed_jg_ys = (EditText) baseView.findViewById(R.id.ed_jg_ys);
		rd_zz = (RadioGroup) baseView.findViewById(R.id.rd_zz);
		rb_w = (RadioButton) baseView.findViewById(R.id.rb_w);
		rb_y = (RadioButton) baseView.findViewById(R.id.rb_y);
		ed_zzyy.setEnabled(false);
		ed_jg_ys.setEnabled(false);

		et_hbfy = (EditText) baseView.findViewById(R.id.et_hbfy);
		et_hbfx = (EditText) baseView.findViewById(R.id.et_hbfx);
		et_hbws = (EditText) baseView.findViewById(R.id.et_hbws);
		et_hbqt = (EditText) baseView.findViewById(R.id.et_hbqt);

		btn_tz_more = (Button) baseView.findViewById(R.id.btn_tz_more);
		btn_tz_more.setOnClickListener(this);
		btn_xhdb_more = (Button) baseView.findViewById(R.id.btn_xhdb_more);
		btn_xhdb_more.setOnClickListener(this);
	}

	@Override
	public void addListener() {
		rd_zz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (checkedId == R.id.rb_w) {
					str_zzId = "DM01-11_1";
					ed_zzyy.setText("");
					ed_jg_ys.setText("");
					ed_zzyy.setEnabled(false);
					ed_jg_ys.setEnabled(false);

				} else if (checkedId == R.id.rb_y) {
					str_zzId = "DM01-11_2";
					ed_zzyy.setEnabled(true);
					ed_jg_ys.setEnabled(true);
				} else {
					str_zzId = "";
				}

			}
		});

	}

	@Override
	public void setData() {
		GlobalConts.checkNumOrange(getActivity(), weightEdit, 100, 0);
		GlobalConts.checkNumOrange(getActivity(), shenChangEdit, 100, 0);
		GlobalConts.checkNumOrange(getActivity(), touWeiEdit, 100, 0);
		GlobalConts.checkNumOrange(getActivity(), qianxinLeft, 100, 0);
		GlobalConts.checkNumOrange(getActivity(), qianxinRight, 100, 0);
		GlobalConts.checkNumOrange(getActivity(), xueDanBai, 1000, -1);
		GlobalConts.checkNumOrange(getActivity(), huWai, 24, 0);
		// 肺炎
		GlobalConts.checkNumOrange(getActivity(), et_hbfy, 99, 0);
		// 腹泻
		GlobalConts.checkNumOrange(getActivity(), et_hbfx, 99, 0);
		// 外伤
		GlobalConts.checkNumOrange(getActivity(), et_hbws, 99, 0);
		NovaApplication.dbManger.addColumnByBySQL("CHILD_WITHIN_ONE_YEAR_OLD", "GUIDANCE_OTHER");
	}

	public int getListIndex(String id, List<BD_DD_INFO> bds) {
		int index = 0;
		try {
			for (int i = 0; i < bds.size(); i++) {
				if (id.equals(bds.get(i).getID())) {
					index = i;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return index;
	}

	/**
	 * 字符串转换"1,2,3,4,5" --> "'1','2','3','4','5'"
	 * 
	 * @param symptom
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月19日 下午2:49:23
	 */
	public String checkedIdsSql(String symptom) {
		String[] idarr = symptom.split(",");
		String sql = "";
		for (String id : idarr) {
			sql += "'" + id + "',";
		}
		sql = sql.substring(0, sql.length() - 1);
		System.out.println(sql);
		return sql;
	}

	@Override
	public void save() {
		int months = DateUtil.getMonthsByDate(new Date(), userInfo.getBIRTHDAY());
		if (months != -1) {
			if (months < 6) {
				((ChildActivity) getActivity()).showTextDialog("儿童未满6月龄，不予保存");
				return;
			}

		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), weightEdit, 100, 0)) {
			((ChildActivity) getActivity()).showTextDialog("体重不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), shenChangEdit, 100, 0)) {
			((ChildActivity) getActivity()).showTextDialog("身长不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), touWeiEdit, 100, 0)) {
			((ChildActivity) getActivity()).showTextDialog("头围不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), qianxinLeft, 100, 0)) {
			((ChildActivity) getActivity()).showTextDialog("前囟左不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), qianxinRight, 100, 0)) {
			((ChildActivity) getActivity()).showTextDialog("前囟右不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), xueDanBai, 1000, -1)) {
			((ChildActivity) getActivity()).showTextDialog("血红蛋白不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), huWai, 24, 0)) {
			((ChildActivity) getActivity()).showTextDialog("户外活动不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbfy, 99, 0)) {
			((ChildActivity) getActivity()).showTextDialog("肺炎数据不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbfx, 99, 0)) {
			((ChildActivity) getActivity()).showTextDialog("腹泻数据不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbws, 99, 0)) {
			((ChildActivity) getActivity()).showTextDialog("外伤不合理，保存失败");
			return;
		}

		if (TextUtils.isEmpty(nextSuiFangDAte.getText())){
			((ChildActivity) getActivity()).showTextDialog("请选择下次随访时间！");
			return;
		}
		getCHILD_WITHIN_ONE_YEAR_OLD();
		getCHILD_TCMHM_ONE();
		// ((ChildActivity) getActivity()).showTextDialog("保存成功");
		if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
							intent.putExtra("type", "02");
							intent.putExtra("szfs", "");
							startActivity(intent);
						}
					}).show();
		} else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
			((ChildActivity) getActivity()).showTextDialog("保存成功");
		}
	}

	public void getCHILD_WITHIN_ONE_YEAR_OLD() {
		CHILD_WITHIN_ONE_YEAR_OLD child_WITHIN_ONE_YEAR_OLD = new CHILD_WITHIN_ONE_YEAR_OLD();
		child_WITHIN_ONE_YEAR_OLD.setFOLLOWUP_DATE(suiFang_Date.getDate());
		child_WITHIN_ONE_YEAR_OLD.setIDCARD(userInfo.getIDCARD());
		child_WITHIN_ONE_YEAR_OLD.setFLAG("3");// 满月 1 三月龄2六月龄3八月龄4
		child_WITHIN_ONE_YEAR_OLD.setARCHIVEID("");
		// if (!TextUtils.isEmpty(weightEdit.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setWEIGHT(weightEdit.getText().toString());
		child_WITHIN_ONE_YEAR_OLD.setWEIGHT_ANALYSIS(rbatizhong.getChecked());
		// if (!TextUtils.isEmpty(shenChangEdit.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setSTATURE(shenChangEdit.getText().toString());
		child_WITHIN_ONE_YEAR_OLD.setSTATURE_ANALYSIS(rbashenchang.getChecked());
		// if (!TextUtils.isEmpty(touWeiEdit.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setHEAD_CIRCUMFERENCE(touWeiEdit.getText().toString());
		child_WITHIN_ONE_YEAR_OLD.setCOLOUR_FACE(rbamianse.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setSKIN(rbapf.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setBREGMA(rbaqx.getChecked());
		// if (!TextUtils.isEmpty(qianxinLeft.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setBREGMA_LEFT(qianxinLeft.getText().toString());
		// }else{
		// child_WITHIN_ONE_YEAR_OLD.setBREGMA_LEFT(-1);
		// }
		// if (!TextUtils.isEmpty(qianxinRight.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setBREGMA_RIGHT(qianxinRight.getText().toString());
		// }else{
		// child_WITHIN_ONE_YEAR_OLD.setBREGMA_RIGHT(-1);
		// }
		child_WITHIN_ONE_YEAR_OLD.setLISTENING(rbatl.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setNECK_MASS(rbajbbk.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setEYE_APPEARANCE(rbaywg.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setEAR_APPEARANCE(rbaewg.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setORAL_CAVITY(et_kq.getText().toString());
		child_WITHIN_ONE_YEAR_OLD.setHEART_LUNG(rbaxf.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setSTOMACH(rbafb.getChecked());
		// child_WITHIN_ONE_YEAR_OLD.setUMBILICAL_REGION(rbaqb.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setFOUR_LIMB(rbasz.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setRICKETS_SIGN(ns_kyglbtz.getSelectedIndex() + "");
		child_WITHIN_ONE_YEAR_OLD.setRICKETS_SYMPTOM(ns_kyglbzz.getSelectedIndex() + "");
		child_WITHIN_ONE_YEAR_OLD.setANUS_EXTERNAL_GENITA(rbagm.getChecked());
		// if (!TextUtils.isEmpty(xueDanBai.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setHEMOGLOBIN_VALUE(xueDanBai.getText().toString());
		// }else{
		// child_WITHIN_ONE_YEAR_OLD.setHEMOGLOBIN_VALUE(-1);
		// }
		// if (!TextUtils.isEmpty(huWai.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setOUTDOOR_ACTIVITIES(huWai.getText().toString());
		// }else{
		// child_WITHIN_ONE_YEAR_OLD.setOUTDOOR_ACTIVITIES(-1);
		// }
		// if (!TextUtils.isEmpty(vcEditText.getText())) {
		child_WITHIN_ONE_YEAR_OLD.setTAKING_VITAMINSD(vcEditText.getText().toString());
		// }else{
		// child_WITHIN_ONE_YEAR_OLD.setTAKING_VITAMINSD(-1);
		// }
		child_WITHIN_ONE_YEAR_OLD.setAUXE_ESTIMATE_OTHER(rbafy.getCheckedIdsStr());
		child_WITHIN_ONE_YEAR_OLD.setAMONGTWOFOLLOWUP(rbalc.getChecked());
		child_WITHIN_ONE_YEAR_OLD.setIS_UPDATE("Y");

		if (rb_w.isChecked()) {
			str_zzId = "DM01-11_1";
		} else if (rb_y.isChecked()) {
			str_zzId = "DM01-11_2";
		} else {
			str_zzId = "";
		}

		// 两次随访
		String strfy = et_hbfy.getText().toString();
		child_WITHIN_ONE_YEAR_OLD.setPNEUMONIA_FREQUEN(strfy);
		String strff = et_hbfx.getText().toString();
		child_WITHIN_ONE_YEAR_OLD.setDIARRHOEA_FREQUEN(strff);
		String strws = et_hbws.getText().toString();
		child_WITHIN_ONE_YEAR_OLD.setTRAUMATISM_FREQUEN(strws);
		child_WITHIN_ONE_YEAR_OLD.setAMONG_TWO_FOLLO_OTHER(et_hbqt.getText().toString());

		child_WITHIN_ONE_YEAR_OLD.setREFERRAL_ADVICE(str_zzId);
		child_WITHIN_ONE_YEAR_OLD.setREFERRAL_REASON(ed_zzyy.getText().toString());
		child_WITHIN_ONE_YEAR_OLD.setAGENCIES_DEPARTMENTS(ed_jg_ys.getText().toString());

		child_WITHIN_ONE_YEAR_OLD.setGUIDANCE(cbazhidao.getCheckedIdsStr());
		child_WITHIN_ONE_YEAR_OLD.setGUIDANCE_OTHER(cbazhidao.getOther());
		child_WITHIN_ONE_YEAR_OLD.setNEXT_FOLLOWUP_DATE(nextSuiFangDAte.getDate());
		child_WITHIN_ONE_YEAR_OLD
				.setFOLLOWUP_DOCTOR_SIGN(NovaApplication.getDoctorList().get(doctor.getSelectedIndex()).getUSER_ID());
		child_WITHIN_ONE_YEAR_OLD
				.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(doctor.getSelectedIndex()).getUSER_ID());
		child_WITHIN_ONE_YEAR_OLD.setLAST_UPDATE_DATE(new Date());
		if (NovaApplication.fdbmanger.findAllByWhere(CHILD_WITHIN_ONE_YEAR_OLD.class,
				"IDCARD='" + userInfo.getIDCARD() + "'" + " AND FLAG='" + 3 + "'").size() > 0) {

			child_WITHIN_ONE_YEAR_OLD.setUPDATEORG(userInfo.getCREATEORG());
			child_WITHIN_ONE_YEAR_OLD
					.setMODIFIED(NovaApplication.getDoctorList().get(doctor.getSelectedIndex()).getUSER_ID());

			NovaApplication.fdbmanger.updata(child_WITHIN_ONE_YEAR_OLD,
					"IDCARD='" + userInfo.getIDCARD() + "'" + " AND FLAG='" + 3 + "'");
		} else {
			child_WITHIN_ONE_YEAR_OLD.setCREATED_BY(userInfo.getCREATED_BY());
			child_WITHIN_ONE_YEAR_OLD.setCREATED_DATE(new Date());
			child_WITHIN_ONE_YEAR_OLD.setCREATEORG(userInfo.getCREATEORG());
			child_WITHIN_ONE_YEAR_OLD.setCREATER(userInfo.getCREATER());

			NovaApplication.fdbmanger.save(child_WITHIN_ONE_YEAR_OLD);
		}

	}

	public void getCHILD_TCMHM_ONE() {
		CHILD_TCMHM_ONE child_TCMHM_ONE = new CHILD_TCMHM_ONE();
		child_TCMHM_ONE.setARCHIVEID("");
		child_TCMHM_ONE.setIDCARD(userInfo.getIDCARD());
		child_TCMHM_ONE.setFOLLOWUP_TYPE("3");
		if (!TextUtils.isEmpty(cbazy.getOther())) {
			child_TCMHM_ONE.setTCMHM_OTHER(cbazy.getOther());
		}
		child_TCMHM_ONE.setTCMHM(cbazy.getCheckedIdsStr());
		child_TCMHM_ONE.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(doctor.getSelectedIndex()).getUSER_ID());
		child_TCMHM_ONE.setLAST_UPDATE_DATE(new Date());
		if (NovaApplication.fdbmanger.findAllByWhere(CHILD_TCMHM_ONE.class,
				"IDCARD='" + userInfo.getIDCARD() + "'" + " AND FOLLOWUP_TYPE='" + 3 + "'").size() > 0) {

			child_TCMHM_ONE.setUPDATEORG(userInfo.getCREATEORG());
			child_TCMHM_ONE.setMODIFIED(NovaApplication.getDoctorList().get(doctor.getSelectedIndex()).getUSER_ID());
			NovaApplication.fdbmanger.updata(child_TCMHM_ONE,
					"IDCARD='" + userInfo.getIDCARD() + "'" + " AND FOLLOWUP_TYPE='" + 3 + "'");
		} else {

			child_TCMHM_ONE.setCREATED_BY(userInfo.getCREATED_BY());
			child_TCMHM_ONE.setCREATED_DATE(new Date());
			child_TCMHM_ONE.setCREATEORG(userInfo.getCREATEORG());
			child_TCMHM_ONE.setCREATER(userInfo.getCREATER());
			NovaApplication.fdbmanger.save(child_TCMHM_ONE);
		}
	}

	@Override
	public void onStart() {
		super.onStart();
		List<CHILD_WITHIN_ONE_YEAR_OLD> child_WITHIN_ONE_YEAR_OLDs = NovaApplication.fdbmanger.findAllByWhere(
				CHILD_WITHIN_ONE_YEAR_OLD.class, "IDCARD='" + userInfo.getIDCARD() + "'" + " AND FLAG='" + 3 + "'");
		List<CHILD_TCMHM_ONE> child_TCMHM_ONEs = NovaApplication.fdbmanger.findAllByWhere(CHILD_TCMHM_ONE.class,
				"IDCARD='" + userInfo.getIDCARD() + "'" + " AND FOLLOWUP_TYPE='" + 3 + "'");
		if (child_WITHIN_ONE_YEAR_OLDs.size() > 0) {
			CHILD_WITHIN_ONE_YEAR_OLD child_WITHIN_ONE_YEAR_OLD = child_WITHIN_ONE_YEAR_OLDs.get(0);
			if (child_WITHIN_ONE_YEAR_OLD.getFOLLOWUP_DATE() != null) {
				// suiFang_Date.setText(sdf.format(child_WITHIN_ONE_YEAR_OLD.getFOLLOWUP_DATE()));
			}
			// if (child_WITHIN_ONE_YEAR_OLD.getWEIGHT() == -1) {
			// weightEdit.setText("");
			// } else {
			mgvtizhong.setAdapter(rbatizhong);
			rbatizhong.setChecked(child_WITHIN_ONE_YEAR_OLD.getWEIGHT_ANALYSIS());
			mgvshenchang.setAdapter(rbashenchang);
			rbashenchang.setChecked(child_WITHIN_ONE_YEAR_OLD.getSTATURE_ANALYSIS());
			weightEdit.setText(child_WITHIN_ONE_YEAR_OLD.getWEIGHT() + "");

			shenChangEdit.setText(child_WITHIN_ONE_YEAR_OLDs.get(0).getSTATURE() + "");

			touWeiEdit.setText(child_WITHIN_ONE_YEAR_OLD.getHEAD_CIRCUMFERENCE() + "");
			mgvmianse.setAdapter(rbamianse);
			rbamianse.setChecked(child_WITHIN_ONE_YEAR_OLD.getCOLOUR_FACE());
			mgvpifu.setAdapter(rbapf);
			rbapf.setChecked(child_WITHIN_ONE_YEAR_OLD.getSKIN());
			mgvqianxin.setAdapter(rbaqx);
			mgvtingli.setAdapter(rbatl);
			rbatl.setChecked(child_WITHIN_ONE_YEAR_OLD.getLISTENING());
			rbaqx.setChecked(child_WITHIN_ONE_YEAR_OLD.getBREGMA());

			// 两次随访患者
			et_hbfy.setText(child_WITHIN_ONE_YEAR_OLD.getPNEUMONIA_FREQUEN());
			et_hbfx.setText(child_WITHIN_ONE_YEAR_OLD.getDIARRHOEA_FREQUEN());// strff.isEmpty()
			et_hbws.setText(child_WITHIN_ONE_YEAR_OLD.getTRAUMATISM_FREQUEN());
			et_hbqt.setText(child_WITHIN_ONE_YEAR_OLD.getAMONG_TWO_FOLLO_OTHER());

			// if (child_WITHIN_ONE_YEAR_OLD.getBREGMA_LEFT() == -1) {
			// qianxinLeft.setText("");
			// } else {
			qianxinLeft.setText(child_WITHIN_ONE_YEAR_OLD.getBREGMA_LEFT() + "");
			// }
			// if (child_WITHIN_ONE_YEAR_OLD.getBREGMA_RIGHT() == -1) {
			// qianxinRight.setText("");
			// } else {
			qianxinRight.setText(child_WITHIN_ONE_YEAR_OLD.getBREGMA_RIGHT() + "");
			// }
			mgvjingbubaokuai.setAdapter(rbajbbk);
			rbajbbk.setChecked(child_WITHIN_ONE_YEAR_OLD.getNECK_MASS());
			mgvyanwaiguan.setAdapter(rbaywg);
			rbaywg.setChecked(child_WITHIN_ONE_YEAR_OLD.getEYE_APPEARANCE());
			mgverwaiguan.setAdapter(rbaewg);
			rbaewg.setChecked(child_WITHIN_ONE_YEAR_OLD.getEAR_APPEARANCE());
			et_kq.setText(child_WITHIN_ONE_YEAR_OLD.getORAL_CAVITY());
			// mgvkouqiang.setAdapter(rbakq);
			// rbakq.setChecked(child_WITHIN_ONE_YEAR_OLD.getORAL_CAVITY());
			mgvxinfei.setAdapter(rbaxf);
			rbaxf.setChecked(child_WITHIN_ONE_YEAR_OLD.getHEART_LUNG());
			mgvfubu.setAdapter(rbafb);
			rbafb.setChecked(child_WITHIN_ONE_YEAR_OLD.getSTOMACH());
			// mgvqibu.setAdapter(rbaqb);
			// rbaqb.setChecked(child_WITHIN_ONE_YEAR_OLD.getUMBILICAL_REGION());
			mgvsizhi.setAdapter(rbasz);
			rbasz.setChecked(child_WITHIN_ONE_YEAR_OLD.getFOUR_LIMB());
			ns_kyglbtz.setSelectedIndex(Integer.parseInt(child_WITHIN_ONE_YEAR_OLD.getRICKETS_SIGN()));
			ns_kyglbzz.setSelectedIndex(Integer.parseInt(child_WITHIN_ONE_YEAR_OLD.getRICKETS_SYMPTOM()));
			mgv_gangmen.setAdapter(rbagm);
			rbagm.setChecked(child_WITHIN_ONE_YEAR_OLD.getANUS_EXTERNAL_GENITA());
			// if (child_WITHIN_ONE_YEAR_OLD.getHEMOGLOBIN_VALUE() == -1) {
			// xueDanBai.setText("");
			// } else {
			xueDanBai.setText(child_WITHIN_ONE_YEAR_OLD.getHEMOGLOBIN_VALUE() + "");
			// }
			// if (child_WITHIN_ONE_YEAR_OLD.getOUTDOOR_ACTIVITIES() == -1) {
			// huWai.setText("");
			// } else {
			huWai.setText(child_WITHIN_ONE_YEAR_OLD.getOUTDOOR_ACTIVITIES() + "");
			// }
			// if (child_WITHIN_ONE_YEAR_OLD.getTAKING_VITAMINSD() == -1) {
			// vcEditText.setText("");
			// } else {
			vcEditText.setText(child_WITHIN_ONE_YEAR_OLD.getTAKING_VITAMINSD() + "");
			// }
			mgv_fayupinggu.setAdapter(rbafy);
			rbafy.setChecked(child_WITHIN_ONE_YEAR_OLD.getAUXE_ESTIMATE_OTHER());
			mgv_liangcisuifang.setAdapter(rbalc);
			rbalc.setChecked(child_WITHIN_ONE_YEAR_OLD.getAMONGTWOFOLLOWUP());
			
			if ("DM01-11_2".equals(child_WITHIN_ONE_YEAR_OLD.getAMONGTWOFOLLOWUP())) {
				for (int i = 0; i < lstTv.size(); i++) {
					lstTv.get(i).setEnabled(true);
					lstTv.get(i).setFocusable(true);
					lstTv.get(i).setFocusableInTouchMode(true);
					lstTv.get(i).setClickable(true);
				}
			}else if ("DM01-11_1".equals(child_WITHIN_ONE_YEAR_OLD.getAMONGTWOFOLLOWUP())) {
				for (int i = 0; i < lstTv.size(); i++) {
					lstTv.get(i).setEnabled(false);
					lstTv.get(i).setFocusable(false);
					lstTv.get(i).setFocusableInTouchMode(false);
					lstTv.get(i).setClickable(false);
				}
			}


			str_zzId = child_WITHIN_ONE_YEAR_OLD.getREFERRAL_ADVICE();

			if (!TextUtils.isEmpty(str_zzId)) {
				if (str_zzId.equals("DM01-11_1")) {
					rb_w.setChecked(true);
				} else if (str_zzId.equals("DM01-11_2")) {
					rb_y.setChecked(true);
				}
			}

			ed_zzyy.setText(child_WITHIN_ONE_YEAR_OLD.getREFERRAL_REASON());
			ed_jg_ys.setText(child_WITHIN_ONE_YEAR_OLD.getAGENCIES_DEPARTMENTS());
			mgv_zhidao.setAdapter(cbazhidao);
			cbazhidao.setChecked(child_WITHIN_ONE_YEAR_OLD.getGUIDANCE());
			cbazhidao.setOther(child_WITHIN_ONE_YEAR_OLD.getGUIDANCE_OTHER());
			if (child_WITHIN_ONE_YEAR_OLD.getNEXT_FOLLOWUP_DATE() != null) {
				nextSuiFangDAte.setText(sdf.format(child_WITHIN_ONE_YEAR_OLD.getNEXT_FOLLOWUP_DATE()));
			}
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (child_WITHIN_ONE_YEAR_OLD.getFOLLOWUP_DOCTOR_SIGN()
						.equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					doctor.setSelectedIndex(i);
				}

			}

		} else {
			suiFang_Date.setText(sdf.format(new Date(System.currentTimeMillis())));
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					doctor.setSelectedIndex(i);
				}

			}
		}
		if (child_TCMHM_ONEs.size() > 0) {
			CHILD_TCMHM_ONE child_TCMHM_ONE = child_TCMHM_ONEs.get(0);
			cbazy.setOther(child_TCMHM_ONE.getTCMHM_OTHER());
			zhongyi.setAdapter(cbazy);
			cbazy.setChecked(child_TCMHM_ONE.getTCMHM());
		}
	}

	public void bind() {
		lstyw = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-11' order by cast(SORT as int) asc");
		lstyc = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-40' order by cast(SORT as int) asc");
		// lstqb =
		// FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
		// "PARENTID = 'DM05-18' order by cast(SORT as int) asc");
		lstszx = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-39' order by cast(SORT as int) asc");
		// 体重
		rbatizhong = new RadioButtonAdapter(lstszx, getActivity());
		rbatizhong.setOtherTextVisible(false);
		mgvtizhong.setAdapter(rbatizhong);
		// 身长
		rbashenchang = new RadioButtonAdapter(lstszx, getActivity());
		rbashenchang.setOtherTextVisible(false);
		mgvshenchang.setAdapter(rbashenchang);
		// 面色DM05-14_2
		List<BD_DD_INFO> lstms = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-14_2' order by cast(SORT as int) asc");
		rbamianse = new RadioButtonAdapter(lstms, getActivity());
		rbamianse.setOtherTextVisible(false);
		mgvmianse.setAdapter(rbamianse);
		// 前囟DM05-16_1
		List<BD_DD_INFO> lstqx = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-16_1' order by cast(SORT as int) asc");
		rbaqx = new RadioButtonAdapter(lstqx, getActivity());
		rbaqx.setOtherTextVisible(false);
		mgvqianxin.setAdapter(rbaqx);
		// 眼外观lstyc
		rbaywg = new RadioButtonAdapter(lstyc, getActivity());
		rbaywg.setOtherTextVisible(false);
		mgvyanwaiguan.setAdapter(rbaywg);
		// 听力DM01-30
		List<BD_DD_INFO> lsttl = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-30' order by cast(SORT as int) asc");
		rbatl = new RadioButtonAdapter(lsttl, getActivity());
		rbatl.setOtherTextVisible(false);
		mgvtingli.setAdapter(rbatl);
		// 心肺lstyc
		rbaxf = new RadioButtonAdapter(lstyc, getActivity());
		rbaxf.setOtherTextVisible(false);
		mgvxinfei.setAdapter(rbaxf);
		// // 脐部lstyc
		// rbaqb = new RadioButtonAdapter(lstqb, getActivity());
		// rbaqb.setOtherTextVisible(false);
		// mgvqibu.setAdapter(rbaqb);
		// 肛门/外生殖lstyc
		rbagm = new RadioButtonAdapter(lstyc, getActivity());
		rbagm.setOtherTextVisible(false);
		mgv_gangmen.setAdapter(rbagm);
		// mgvpifu
		rbapf = new RadioButtonAdapter(lstyc, getActivity(), et_pf);
		rbapf.setOtherTextVisible(false);
		mgvpifu.setAdapter(rbapf);
		// 颈部包块lstyw
		rbajbbk = new RadioButtonAdapter(lstyw, getActivity());
		rbajbbk.setOtherTextVisible(false);
		mgvjingbubaokuai.setAdapter(rbajbbk);
		// 耳外观
		rbaewg = new RadioButtonAdapter(lstyc, getActivity(), et_ewg);
		rbaewg.setOtherTextVisible(false);
		mgverwaiguan.setAdapter(rbaewg);
		// 口腔
		// rbakq = new RadioButtonAdapter(lstyc, getActivity(), et_kq);
		// rbakq.setOtherTextVisible(false);
		// mgvkouqiang.setAdapter(rbakq);
		// 腹部
		rbafb = new RadioButtonAdapter(lstyc, getActivity(), et_fb);
		rbafb.setOtherTextVisible(false);
		mgvfubu.setAdapter(rbafb);
		// 四肢
		rbasz = new RadioButtonAdapter(lstyc, getActivity(), et_sz);
		rbasz.setOtherTextVisible(false);
		mgvsizhi.setAdapter(rbasz);
		// 可疑佝偻病症状DM05-21
		List<BD_DD_INFO> lstkyglbzz = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-21' order by cast(SORT as int) asc");
		ns_kyglbzz.attachDataSource(getDataInfo(lstkyglbzz));
		// 可疑佝偻病体征DM05-19_2
		List<BD_DD_INFO> lstkyglbtz = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-19_2' order by cast(SORT as int) asc");
		BD_DD_INFO bd_DD_INFO = new BD_DD_INFO();
		bd_DD_INFO.setDATAINFO("无");
		lstkyglbtz.add(0, bd_DD_INFO);
		ns_kyglbtz.attachDataSource(getDataInfo(lstkyglbtz));
		ns_kyglbtz.setText("无");
		// 发育评估 DM01-30
		List<BD_DD_INFO> lstfy = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-26_2' order by cast(SORT as int) asc");
		rbafy = new CheckBoxAdapter(getActivity(), lstfy);
		rbafy.setOtherVis(false);
		mgv_fayupinggu.setAdapter(rbafy);
		// 两次随访DM05-20
		List<BD_DD_INFO> lstlc = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-11' order by cast(SORT as int) asc");
		lstTv = new ArrayList<EditText>();
		lstTv.add(et_hbfy);
		lstTv.add(et_hbfx);
		lstTv.add(et_hbws);
		lstTv.add(et_hbqt);
		rbalc = new RadioButtonAdapter(lstlc, getActivity(), lstTv);
		rbalc.setOtherTextVisible(false);
		mgv_liangcisuifang.setAdapter(rbalc);

		// 健康指导
		List<BD_DD_INFO> lstzd = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-04' order by cast(SORT as int) asc");
		List<BD_DD_INFO> listZZs_new = new ArrayList<BD_DD_INFO>();
		int size = lstzd.size();
		if (size > 0) {
			for (int i = 0; i < size; i++) {

				// DM05-04_1 科学喂养 ；DM05-04_2 合理膳食 ；DM05-04_3 生长发育
				// DM05-04_4 疾病预防;DM05-04_5 预防意外伤害;DM05-04_6 口腔保健
				// DM05-04_9 其他
				if (lstzd.get(i).getID().equals("DM05-04_1") || lstzd.get(i).getID().equals("DM05-04_3")
						|| lstzd.get(i).getID().equals("DM05-04_4") || lstzd.get(i).getID().equals("DM05-04_5")
						|| lstzd.get(i).getID().equals("DM05-04_6") || lstzd.get(i).getID().equals("DM05-04_9")) {
					listZZs_new.add(lstzd.get(i));
				}
			}
		}
		cbazhidao = new CheckBoxAdapter(getActivity(), listZZs_new);
		mgv_zhidao.setAdapter(cbazhidao);
		// 中医DM200-04
		List<BD_DD_INFO> lstzy = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM06-06' and SORT!='5' and SORT!='6' and SORT!='4' order by cast(SORT as int) asc");
		cbazy = new CheckBoxAdapter(getActivity(), lstzy);
		zhongyi.setAdapter(cbazy);
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
		int id = v.getId();
		if (id == R.id.btn_tz_more) {
			intent.putExtra("flag", "体重");
			getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
		} else if (id == R.id.btn_xhdb_more) {
			intent.putExtra("flag", "血红蛋白");
			getActivity().startActivityForResult(intent, GlobalConts.RequestXueHongDanbai);
		} else {
		}

	}

	@Override
	public void setTizhong(String value) {
		weightEdit.setText(value);

	}

	@Override
	public void setXueHongDanBai(String xhdb) {
		if (!TextUtils.isEmpty(xhdb)) {
			xueDanBai.setText(String.valueOf((int) (Double.parseDouble(xhdb) * 10)));
		}
	}

}